package think.reuse;

import java.util.Random;

class Value{
    int i;
    Value(int i){
        this.i=i;
    }
}

public class FinalData {
    private static Random rand=new Random(47);
    private String id;

    FinalData(String id){
        this.id=id;
    }

    //可成为编译常量
    private final int valueOne=9;
    private static final int valueTwo=99;
    public static final int valueThree=39;

    //不能成为编译常量
    private final int valueFour=rand.nextInt(20);
    static final int valueFive=rand.nextInt(20);
    private Value v1=new Value(11);
    private final Value v2=new Value(22);
    private static final Value v3=new Value(33);

    //数组类型
    private final int a[]={1,2,3,4,5,6};

    @Override
    public String toString(){
        return
                id+": "+"valueFour="+valueFour+"valueFive= "+valueFive;
    }

    public static void main(String[] args) {
        FinalData fd1=new FinalData("fd1");

        fd1.v2.i++;
        fd1.v1=new Value(9);
        for(int i=0;i<fd1.a.length;i++){
            fd1.a[i]++;
        }
        System.out.println(fd1);
        System.out.println("Creating a new object");
        FinalData fd2=new FinalData("fd2");
        System.out.println(fd1);
        System.out.println(fd2);
    }
}
